package com.study.rabbitmq.config;


import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.Connection;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableMBeanExport;

import java.net.URI;
import java.nio.channels.Channel;

@Configuration
public class ConsumerConfig {

    @Bean
    public ConnectionFactory getConnectionFactory(){

        ConnectionFactory connectionFactory = new CachingConnectionFactory(URI.create("amqp://root:123456@192.168.181.131:5672/%2f"));
        return connectionFactory;
    }


    @Bean
    @Autowired
    public RabbitTemplate getRabbitTemplate(ConnectionFactory connectionFactory){
        return new RabbitTemplate(connectionFactory);
    }

    @Bean
    @Autowired
    public RabbitAdmin getRabbitAdmin(ConnectionFactory connectionFactory){

        return new RabbitAdmin(connectionFactory);
    }

    @Bean
    public Queue getQueue(){
        return QueueBuilder.nonDurable("queue.anno").build();
    }
}
